package com.achievo.know.application;


import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import org.apache.commons.lang.StringUtils;

import com.dayatang.domain.InstanceFactory;

public class CodeDictCacheHandler {
	private static Cache cache;
	
	private static final Object obj = new Object();
	
	static {
		codeDictInitialize();
	}
	
	public static void codeDictInitialize() {
		
	}

	public static Cache getInstance(){
        if (cache == null)
	        synchronized (obj) {
	        	cache = (Cache)InstanceFactory.getInstance(Cache.class, "dataCache");
			}
        return cache;
	}
	
	public static Object getObject(final String key){
		if (StringUtils.isNotBlank(key)){
			Element e = getInstance().get(key);
			if (e != null) return e.getValue();
			else return null;
		}else return null;

	}

	public static void putObject(final String key,Object data){
		if (StringUtils.isNotBlank(key) && data != null)
			getInstance().put(new Element(key,data));
	}	
	
	public static void removeObject(final String key){
		if (StringUtils.isNotBlank(key)){
			getInstance().remove(key);
		}
	}
}
